﻿using CCSSolderUI.ViewModels.Dialogs;
using CCSSolderUI.ViewModels.Dialogs.JobConfig;
using CCSSolderUI.ViewModels.Dialogs.MScanner;
using CCSSolderUI.ViewModels.Dialogs.PartNumber;
using CCSSolderUI.Views;
using CCSSolderUI.Views.Dialogs;
using CCSSolderUI.Views.Dialogs.JobConfig;
using CCSSolderUI.Views.Dialogs.MScanner;
using CCSSolderUI.Views.Dialogs.PartNumber;
using Prism.Ioc;
using Prism.Unity;
using System;
using System.Threading;
using System.Windows;

namespace CCSSolderUI
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        private static Mutex _mutex = null;
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }
        protected override void OnStartup(StartupEventArgs e)
        {
            const string appName = "CCSSolderUI";
            bool createdNew;

            _mutex = new Mutex(true, appName, out createdNew);

            if (!createdNew)
            {
                MessageBox.Show("CCSSolderUI件已开启", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                //app is already running! Exiting the application  
                Environment.Exit(-1);
            }

            base.OnStartup(e);
        }
        protected override void OnInitialized()
        {            
            base.OnInitialized();
        }
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterDialog<AboutDialog, AboutDialogViewModel>();
            containerRegistry.RegisterDialog<PasswordDialog, PasswordDialogViewModel>();
            containerRegistry.RegisterDialog<AxisDialog, AxisDialogViewModel>();
            containerRegistry.RegisterDialog<CameraCalibrationDialog, CameraCalibrationDialogViewModel>();
            containerRegistry.RegisterDialog<JobConfigDialog, JobConfigDialogViewModel>();
            containerRegistry.RegisterDialog<AddPointDialog, AddPointDialogViewModel>();
            containerRegistry.RegisterDialog<MSensorDialog, MSensorDialogViewModel>();
            containerRegistry.RegisterDialog<PartNumberDialog, PartNumberDialogViewModel>();
            containerRegistry.RegisterDialog<AddNewPNDialog, AddNewPNDialogViewModel>();
            containerRegistry.RegisterDialog<CameraOperationDialog, CameraOperationDialogViewModel>();
            containerRegistry.RegisterDialog<MScannerDialog, MScannerDialogViewModel>();
            containerRegistry.RegisterDialog<MPLCDialog, MPLCDialogViewModel>();
            containerRegistry.RegisterDialog<MParamDialog, MParamDialogViewModel>();
            containerRegistry.RegisterDialog<AlarmDialog, AlarmDialogViewModel>();
            containerRegistry.RegisterDialog<AddNewBarcodeSyntaxDialog, AddNewBarcodeSyntaxDialogViewModel>();
        }
    }
}
